﻿using UnityEngine;
using System.Collections;

public class BgTriggerOfLoop : MonoBehaviour
{

    GameObject bg;
    void Start()
    {
        bg = new GameObject(); 
    
    }

    void Update()
    {

    }

    float t;
    void OnTriggerEnter(Collider collider)//循环plane,走过前边的Plane1把他移到后一个Plane2的后边
    {
        if (collider.gameObject.CompareTag("Player"))
        {
            if (this.gameObject.transform.parent.CompareTag("Plane2"))//父类  
            {
                bg = GameObject.FindGameObjectWithTag("Plane2");
                foreach(Transform item in bg.transform )//每次都设置plane的子物体为可见
                {
                    item.gameObject.GetComponent<MeshRenderer>().enabled = true;
                }
                //bg.transform.position = new Vector3(0, 0, bg.transform.position.z + 200);
                bg.transform.position = new Vector3(0, 0, bg.transform.position.z + Mathf.Clamp(t,210,220));//200，是刚好接上，大于200，空一段距离，设置一些壕沟
                //collider.gameObject.GetComponent<MeshRenderer>().enabled = false;//设置为false,使物体看不见

            }

            else
            {
                bg = GameObject.FindGameObjectWithTag("Plane1");
                foreach (Transform item in bg.transform)//每次都设置plane的子物体为可见
                {
                    item.gameObject.GetComponent<MeshRenderer>().enabled = true;
                }
                bg.transform.position = new Vector3(0, 0, bg.transform.position.z + Mathf.Clamp(t, 210, 220));//200，是刚好接上，大于200，空一段距离，设置一些壕沟
            }  
               
        }
      
    }

  
 
}
